import request from './request'
import env from '../env'
import store from '@/store'

export const usersByDept = () => {
  return request.get('zxch/user/app/dept/users')
}

export const updatePwd = (params) => {
  return request.put('zxch/user/app/updatePwd',params)
}

export const userList = (params) => {
  return request.get('zxch/user/app/users',params)
}

export const listByNames = (params) => {
  return request.post('zxch/user/app/listByNames',params)
}

export const getSpList = (params) => {
  return request.get('/zxch/spList/app/list',params)
}

/**
 * 修改我的客户端id
 */
export const updateClientId = (params) => {
	return request.put('system/user/update-clientid',params)
}

/**
 * 更新头像
 * @param {Object} params - 参数 file url
 */
export const avatar = async (url, uploadUrl = `zxch/user/app/avatar`) => {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: `${env.baseURL}/${uploadUrl}`,
      filePath: url,
      name: 'file',
      header: {
        Authorization: `Bearer ${store.state.userInfo.token}`
      },
      success: res => {
        let data
        if (typeof res.data === 'string') {
          data = JSON.parse(res.data)
        }
        setTimeout(() => {
          resolve(data.data)
        }, 1000)
      }
    })
  })
}